package xyz.lwm.lazycat.netpipe.common.serial;

import xyz.lwm.lazycat.utility.It;

import java.util.HashMap;
import java.util.Map;

/**
 * 序列化工厂
 *
 * @author lwm
 */
public abstract class SerializationFactory {

    private static final Map<SerialType, Serialization> SERIALIZATION_MAP = new HashMap<>();

    static {
        register(SerialType.PROTOSTUFF, new ProtostuffSerialization());
    }

    public static void register(SerialType serialType, Serialization serialization) {
        SERIALIZATION_MAP.put(serialType, serialization);
    }

    public static Serialization getSerialization(SerialType serialType) {
        return It.of(SERIALIZATION_MAP.get(serialType)).getOrThrow(() ->
                new IllegalArgumentException("not registered serialType: " + serialType));
    }

}
